from GetModelValue import is_error_blp,is_error_tga
from struct import pack,unpack,calcsize
import os

def main(importpath,exportpath):
    with open("Texture.mdx",'rb') as fi:
        byte = fi.read()

    texturename = pack('260s',"Alice_portrait.blp".encode())

# 判一下TGA和blp大小是否正确

    for root, dirs, files in os.walk(importpath):
        for file in files:
            if not is_error_blp(root + '\\' + file):
                r_byte = byte.replace(texturename,pack('260s',file.encode()))
                with open( "%s\\%s" % ((exportpath or root),(file[:-4] + '.mdx')),'wb') as fi:
                    fi.write(r_byte)
            elif not is_error_tga(root + '\\' + file):
                r_byte = byte.replace(texturename,pack('260s',file.encode()))
                with open( "%s\\%s" % ((exportpath or root),(file[:-4] + '.mdx')),'wb') as fi:
                    fi.write(r_byte)


importpath = "G:\\素材汇集\\制作模型图打包点\\地面纹理贴图\\无缝贴图纹理(需要自己加工)\\blp1"

main(importpath,None)